package com.tianyi.sfzy1.controller;

import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Psychologicalquestion;
import com.tianyi.sfzy1.service.PsychologicalquestionService;
import com.tianyi.sfzy1.util.R;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/psychologyquestion")
public class PsychologicalquestionController {
    @Autowired
    PsychologicalquestionService psychologicalquestionService;

    @PostMapping
    R add( Psychologicalquestion psychologicalquestion) {
        int i=psychologicalquestionService.add(psychologicalquestion);
        if(i>0)
        {
            return R.ok(null);
        }
       else {
           return R.fail("添加失败");
        }
    }
    @GetMapping("/all")
    R getAll() {
        List<Psychologicalquestion> lists=psychologicalquestionService.findAll();
        return R.ok(lists);
    }

    @DeleteMapping
    R delete(Long id){
        int i=psychologicalquestionService.delete(id);
        if(i>0)
        {
            return R.ok(null);
        }
        else {
            return R.fail("删除失败");
        }

    }
//    部分插入
   @PostMapping("/bufen")
    R insert(Psychologicalquestion psychologicalquestion) {
        int i=psychologicalquestionService.insertSelective(psychologicalquestion);
       if(i>0)
       {
           return R.ok(null);
       }
       else {
           return R.fail("添加失败");
       }
   }
   @PutMapping
    R updateSlecective(Psychologicalquestion psychologicalquestion) {
        int i=psychologicalquestionService.updateByPrimaryKeySelective(psychologicalquestion);
       if(i>0)
       {
           return R.ok(null);
       }
       else {
           return R.fail("修改失败");
       }

   }
   @DeleteMapping("/many")
     public R deleteMany(@RequestBody List<Integer> ids) {
       System.out.println(ids);

        int i=psychologicalquestionService.deleteMany(ids);
        if (i>0){
            return R.ok(null);
        }
        else {
            return R.fail("删除失败");
        }


   }
//   分页查询
    @GetMapping("/fenye")
    public R fenyeSearch(int pageNum,int pageSize){

        PageInfo<Psychologicalquestion> list=psychologicalquestionService.fenyesearch(pageNum,pageSize);
        return R.ok(list);
    }
//    模糊查询
    @GetMapping("/mohu")
    public R mohuSearch(Psychologicalquestion record){
        List<Psychologicalquestion> list=psychologicalquestionService.mohusearch(record);
        return R.ok(list);
    }
//    多表查询 包含名字所有
    @GetMapping("/allMember")
    public R getAllMember(Psychologicalquestion record){
        List<Psychologicalquestion> list=psychologicalquestionService.searchAndMemberAll(record);
        return R.ok(list);
    }
//    多表分页查询含有名字
    @GetMapping("/fenyeallMember")
    public R getFenyeallMember( Psychologicalquestion record, int pageNum,int pageSize){
        System.out.println(record);
       PageInfo<Psychologicalquestion> list=psychologicalquestionService.fenyesearchAndMember(record,pageNum,pageSize);
       return R.ok(list);
    }
    //       通过问题名或者问题内容或者关联会员表的会员用户名查询问题信息-->
//    孟迪
    @GetMapping("/mohuMember")
    public R getMohuMember(@Param("questionTitle") String questionTitle, @Param("questionContent") String questionContent, @Param("memberName") String memberName){
        List<Psychologicalquestion> list=psychologicalquestionService.searchAllByMember1(questionTitle,questionContent,memberName);
        return R.ok(list);
    }

}
